package mushystuff.dtb.web.components;

import java.util.List;

import mushystuff.dtb.core.model.Product;
import mushystuff.dtb.core.service.ProductService;

import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;

@SuppressWarnings("unused")
public class ProductList {
    
    @Parameter("true")
    @Property
    private boolean add;
    
    @Property
    private List<Product> products;
    
    @Property
    private Product product;
    
    @Property
    private Product newProduct;
    
    @Inject
    private ProductService productService;
    
    @SetupRender
    void loadProducts() {
        products = productService.getAllProducts();
        newProduct = new Product();
    }
    
    @OnEvent(component="newProduct", value="success")
    void saveProduct() {
        productService.createUpdateProduct(newProduct);
        newProduct = new Product();
    }

}
